﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input;

namespace X3DXamlXna
{
    //public interface ITimerComponent { }

    //class TimerComponent : GameComponent, ITimerComponent
    //{
    //    //private List<Timer> timers { get; set; }

    //    //public TimerComponent(Game game)
    //    //    : base(game)
    //    //{
    //    //    game.Services.AddService(typeof(ITimerComponent), this);
    //    //}
    //    //public void inizialize()
    //    //{
    //    //    base.Initialize();
    //    //}
    //    //public void update(GameTime gametime)
    //    //{
    //    //    base.Update(gametime);
    //    //}

    //}
    public class Timer
    {
        public DateTime timeStartedAt { get; set; }
        public string DEF { get; set; }

        private float oldTime;
        private bool _enabled;
        public bool enabled
        {
            get { return _enabled; }
            set
            {
                _enabled = value;
                if (!_enabled) oldTime = fraction_changed;
                else
                {
                    var temp = fraction_changed * cycleInterval;
                    timeStartedAt = DateTime.Now.Subtract(System.TimeSpan.FromSeconds(temp));
                }
                
            }
        }


        public float fraction_changed
        {
            get
            {
                var tmp = (DateTime.Now.Subtract(timeStartedAt));
                float app =  tmp.Seconds + tmp.Milliseconds/1000;
                var temp = app % cycleInterval;
                return temp / cycleInterval;
            }
            private set { }
        }

        public float cycleInterval { get; set; }
        public bool loop { get; private set; }

        public float startTime { get; private set; }
        public float stopTime { get; private set; }
        public float pauseTime { get; private set; }
        public float resumeTime { get; private set; }

        public float cycleTime { get; private set; }
        public bool isActive { get; private set; }
        public bool isPaused { get; private set; }
        public float time { get; private set; }
        public string containerField { get; private set; }
        
    }
}
